package com.qfedu.openplateform.manager.controller;

import com.github.pagehelper.PageInfo;
import com.qfedu.openplateform.manager.entity.AjaxMessage;
import com.qfedu.openplateform.manager.entity.ApiSystemparam;
import com.qfedu.openplateform.manager.entity.TableData;
import com.qfedu.openplateform.manager.service.ApiSystemparamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/sys/systemparaters")
public class ApiSystemparamController {

    @Autowired
    private ApiSystemparamService apiSystemparamService;

    @RequestMapping("/table")
    public TableData findAllsystemparam(ApiSystemparam apiSystemparam,Integer page, Integer limit){

        PageInfo<ApiSystemparam> pageInfo = apiSystemparamService.findAllApiSystemparam(apiSystemparam, page, limit);

        return new TableData(pageInfo.getTotal(),pageInfo.getList());
    }

    @RequestMapping("/add")
    public AjaxMessage addApiMapping(ApiSystemparam apiSystemparam){
        try {
            apiSystemparamService.addApiSystemparam(apiSystemparam);
            return new AjaxMessage(true, "添加成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new AjaxMessage(false, "添加失败");
    }

    @RequestMapping("/update")
    public AjaxMessage updateApiMapping(ApiSystemparam apiSystemparam){
        try {
            apiSystemparamService.updateApiSystemparam(apiSystemparam);
            return new AjaxMessage(true, "修改成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new AjaxMessage(false, "修改失败");
    }

    @RequestMapping("/del")
    public AjaxMessage deleteApiMappings(int[] ids){
        try {
            apiSystemparamService.deleteApiSystemparam(ids);
            return new AjaxMessage(true, "删除成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new AjaxMessage(false, "删除失败");

    }

}
